package com.lakeworks.mapper;

import com.lakeworks.common.domain.channel.ProductItem;
import com.lakeworks.domain.OprShipment;
import com.lakeworks.domain.vo.PackageQueryPara;
import com.lakeworks.domain.vo.ShipmentItem;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * 出厂单Mapper接口
 *
 * @author lake
 * @date 2023-02-08
 */
public interface OprShipmentMapper {
    /**
     * 查询出厂单
     *
     * @param id 出厂单主键
     * @return 出厂单
     */
    OprShipment selectOprShipmentById(Long id);

    /**
     * 查询出厂单列表
     *
     * @param oprShipment 出厂单
     * @return 出厂单集合
     */
    List<OprShipment> selectOprShipmentList(OprShipment oprShipment);



    List<OprShipment> selectShipmentList(OprShipment oprShipment);

    /**
     * 新增出厂单
     *
     * @param oprShipment 出厂单
     * @return 结果
     */
    int insertOprShipment(OprShipment oprShipment);

    /**
     * 修改出厂单
     *
     * @param oprShipment 出厂单
     * @return 结果
     */
    int updateOprShipment(OprShipment oprShipment);


    int updateShipmentFrameNo(OprShipment oprShipment);

    /**
     * 删除出厂单
     *
     * @param id 出厂单主键
     * @return 结果
     */
    int deleteOprShipmentById(Long id);

    /**
     * 批量删除出厂单
     *
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    int deleteOprShipmentByIds(String[] ids);

    OprShipment queryByExpressNo(@Param("expressNo") String expressNo);

    OprShipment queryByExpressNoAndStatus(@Param("expressNo") String expressNo, @Param("status") String status);

    OprShipment queryByChannelIdAndChShipmentNo(@Param("channelId") Long channelId, @Param("chShipmentNo") String chShipmentNo);

    @Select("select count(*) from opr_shipment where ch_shipment_no = #{chShipmentNo}")
    int countByChshipmentNo(@Param("chShipmentNo") String chShipmentNo);

    @Select("SELECT opt.barcode,opt.status \n" +
            "FROM opr_shipment ost\n" +
            "LEFT JOIN opr_product opt\n" +
            "ON opt.shipment_id = ost.id\n" +
            "AND opt.flag & 512 != 512\n" +
            "AND opt.companion_id IS NULL\n" +
            "WHERE ost.id = #{id}\n" +
            "AND ost.flag & 512 != 512")
    List<ProductItem> productItemById(@Param("id") Long id);

    OprShipment queryBychShipmentNo(String shipmentNo);


    List<OprShipment> selectBystatus();


    int updateFlagById(OprShipment oprShipment);

    int deleteFlagById(OprShipment oprShipment);

    int shipmentsCountByNoAndHour(String status, PackageQueryPara para);

    List<ShipmentItem> shipmentsByNoAndHour(@Param("status") String status, @Param("para") PackageQueryPara para);

    List<OprShipment> queryShipmentsByDistribution(OprShipment oprShipment);


    Integer selectPlaceShipmentCount(Integer hour);

    Integer selectShipmentCount(@Param("state") String state,@Param("hour") Integer hour);


    Map<String,Object> selectShipmentCustomerCount(@Param("startDays")Integer startDays,@Param("endDays")Integer endDays);

    Map<String,Integer> selectShipmentProductionCount(@Param("startDays")Integer startDays,@Param("endDays")Integer endDays);

}
